package com.example.redis.demos.web.Redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

import static java.lang.Thread.sleep;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-07-13
 * Time:10:15
 * Text：
 */
public class Redis_List {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("120.46.91.1",6379);
        try(Jedis jedis = jedisPool.getResource()){
            jedis.auth("2287448684t");
            test2(jedis);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    private static void test2(Jedis jedis) throws InterruptedException {
        System.out.println("rpush");
        jedis.flushAll();

        jedis.lpush("key","111","222","333");
        List<String> result = jedis.lrange("key",0,-1);
        jedis.lpush("key","444");
        System.out.println(jedis.lpop("key"));

        System.out.println(jedis.blpop(10,"key2"));

        sleep(30);
        jedis.lpush("key2","20");
    }
    private static void test1(Jedis jedis) {
        System.out.println("lpush  | rpush");
        jedis.flushAll();

        jedis.lpush("key","111","222","333");
        List<String> result = jedis.lrange("key",0,-1);
        System.out.println(result);
    }
}
